<template>
	<div class="activityBox">
		<addList @addChang="addChang" v-if="!isEditPage"></addList>
		<admin-activity-set :activity="activeName" :isEdit=" isEditPage" v-else></admin-activity-set>
	</div>
</template>

<script>
	import ala from 'ala'
	import addList from './add.vue'
	export default {
		components: {
			addList
		},
		data() {
			return {
				attributes: null,
				attribute: '', // 编辑的时候用
				isEditPage: false, // 是否为编辑页面
				activeName: null // 活动名称
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				this.activeName = this.$route.query.Key
				if (!this.activeName) {
					this.activeName = this.$route.query.key
				}
				if (!this.activeName) {
					ala.error('活动类型不存在,请输入正确的Url')
				}
				var id = this.$ala.urlId()
				if (id <= 0) {
					var productId = this.$route.query.ProductId
					if (productId > 0) {
						this.isEditPage = true
					} else {
						this.isEditPage = false
					}
				} else {
					this.$router.push(`/Admin/Activity/Edit?key=${this.activeName}&id=${id}`)
					this.isEditPage = true
				}
			},
			addChang(addVal) {
				this.isEditPage = true
				this.$router.push(`/Admin/Activity/Edit?key=${this.activeName}&ProductId=${addVal.id}`)
			}
		}
	}
</script>